using System.Collections.Generic;
using System.Linq;

namespace CodingDojo.Domain.KataAlarmClock
{
  public class AlarmRepository : IAlarmRepository
  {
    private readonly Dictionary<int, Alarm> _alarms;

    public AlarmRepository()
    {
      _alarms = new Dictionary<int, Alarm>();
    }

    public void Add(Alarm alarm)
    {
      _alarms.Add(alarm.Id, alarm);
    }

    public void Delete(int id)
    {
      _alarms.Remove(id);
    }

    public Alarm FindById(int id)
    {
      return _alarms.First(e => e.Key == id).Value;
    }

    public IEnumerable<Alarm> FindAll()
    {
      return _alarms.Select(e => e.Value);
    }
  }
}
